
<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="apple-touch-fullscreen" content="yes" />
	<meta name="format-detection" content="telephone=no"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<meta name="format-detection" content="telephone=no" />
	<meta name="msapplication-tap-highlight" content="no" />
	<meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1" />
	<title>我的代金券</title>
	<link rel="stylesheet" href="/wap/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/base.css">
	<link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/nctouch_member.css">
</head>
<body>
<header id="header">
	<div class="header-wrap">
		<div class="header-l"><a href="member.html"><i class="back"></i></a></div>
		<span class="header-tab"> <a href="voucher_list.php">我的代金券</a> <a href="javascript:void(0);" class="cur">兑换代金券</a> </span>
		<div class="header-r"> <a id="header-nav" href="javascript:void(0);"><i class="more"></i><sup></sup></a> </div>
	</div>
	<div class="nctouch-nav-layout">
		<div class="nctouch-nav-menu"> <span class="arrow"></span>
			<ul>
				<li><a href="/wap"><i class="home"></i>首页</a></li>
				<li><a href="/wap/tmpl/search.php"><i class="search"></i>搜索</a></li>
				<li><a href="../product_first_categroy.php"><i class="categroy"></i>分类</a></li>
				<li><a href="../cart_list.php"><i class="cart"></i>购物车<sup></sup></a></li>
				<li><a href="../member/member.php"><i class="member"></i>我的商城</a></li>
			</ul>
		</div>
	</div>
</header>
<div class="nctouch-main-layout">
	<div class="nctouch-voucher-list">
		<ul class="nctouch-tickets" id="voucher-list">
		</ul>
	</div>
</div>
<div class="fix-block-r"> <a href="javascript:void(0);" class="gotop-btn gotop hide" id="goTopBtn"><i></i></a> </div>
<footer id="footer" class="bottom"></footer>

<script type="text/html" id="voucher-list-tmpl">
	<% if (voucher_list) { %>
	<% for (var k in voucher_list) { var v = voucher_list[k]; %>
	<li class="ticket-item <% if (v.voucher_t_state == 1) { %>normal<% }else{ %>invalid<%}%>" data-vid="<%= v.voucher_t_id %>" data-points="<%= v.voucher_t_points %>">
			<div class="border-left"></div>
			<div class="block-center">
				<div class="store-info">
					<div class="store-avatar"><img src="<%= v.voucher_t_customimg %>" /></div>
					<dl>
						<dt class="store-name"><%= v.voucher_t_title %> --- <%= v.voucher_t_storename %></dt>
						<dd>有效期:<%= tsToDateString(v.voucher_t_end_date)%></dd>
					</dl>
				</div>
				<div class="ticket-info">
					<div class="bg-ico"></div>
					<% if (v.voucher_t_state==2) { %>
					<div class="watermark ysy"></div>
					<% } %>
					<% if (v.voucher_t_state==3 || v.voucher_t_state==4) { %>
					<div class="watermark ysx"></div>
					<% } %>
					<dl>
						<dt>￥<%= v.voucher_t_price %></dt>
						<dd>消耗<%= v.voucher_t_points %>积分、<% if (v.voucher_t_limit) { %>满<%= v.voucher_t_limit %>使用<% } %></dd>
					</dl>
				</div>
			</div>
			<div class="border-right"></div>
		</a>
	</li>
	<% } %>
	<li class="loading"><div class="spinner"><i></i></div>数据读取中</li>
	<% } else { %>
	<div class="nctouch-norecord voucher">
		<div class="norecord-ico"><i></i></div>
		<dl>
			<dt>没有可兑换代金券</dt>
			<dd>店铺代金券可享受商品折扣</dd>
		</dl>
	</div>
	<% } %>
</script>
<script type="text/javascript" src="/wap/e_tpl/js/config.js"></script>
<script type="text/javascript" src="/wap/e_tpl/js/zepto.min.js"></script>
<script type="text/javascript" src="/wap/e_tpl/js/template.js"></script>
<script type="text/javascript" src="/wap/e_tpl/js/common.js"></script>
<script type="text/javascript" src="/wap/e_tpl/js/ncscroll-load.js"></script>
<script src="/data/resource/js/jquery.js"></script>
<script src="/data/resource/layer/layer.js"></script>
<script>
	$(function(){
		var key = getCookie('key');
		if (!key) {
			window.location.href = WapSiteUrl+'/tmpl/member/login.html';
			return;
		}
		//渲染list
		var load_class = new ncScrollLoad();
		load_class.loadInit({
			'url':ApiUrl + '/index.php?act=member_voucher&op=voucher_exchange',
			'getparam':{'key':key},
			'tmplid':'voucher-list-tmpl',
			'containerobj':$("#voucher-list"),
			'iIntervalId':true,
			'data':{WapSiteUrl:WapSiteUrl}
		});

		//代金券兑换功能
		$(".ticket-item").live('click',function(){
			var vid = $(this).data("vid");
			var points = $(this).data("points");
			layer.confirm("确认消耗&nbsp;<b>"+points+"</b>&nbsp;积分兑换吗？",{title:"提示"},function(){
				$.post(ApiUrl + '/index.php?act=member_voucher&op=voucherexchange_save',{'vid':vid,'key':key},function(data){
					if(data==true){
						layer.msg("兑换成功！",function(){
							window.location = "/wap/tmpl/member/voucher_list.php";
						});
					}else{
						layer.msg("兑换失败！",function(){
							window.location = "/wap/tmpl/member/voucher_list.php";
						});
					}

				})
			});
		});
	});
	template.helper('tsToDateString', function (t) {
		var d = new Date(parseInt(t) * 1000);
		var s = '';
		s += d.getFullYear() + '年';
		s += (d.getMonth() + 1) + '月';
		s += d.getDate() + '日';
		return s;
	});

</script>
</body>
</html>
